
#shortcuts and vectors
y.label <- c("DD", "DR", "RR")
y <- c(3:1)
axis.size <- 1.5
line.width <- 2
point.size <- 2
rr.color <- "red"
dr.color <- "purple"
dd.color <- "blue"
color.vector <- c(dd.color, dr.color, rr.color)
all.mean.vector <- c(all.dd.rate, all.dr.rate, all.rr.rate)
all.se.vector <-  c(all.dd.se, all.dr.se, all.dd.se)
dem.mean.vector <- c(dem.dd.rate, dem.dr.rate, dem.rr.rate)
dem.se.vector <-  c(dem.dd.se, dem.dr.se, dem.dd.se)
gop.mean.vector <- c(gop.dd.rate, gop.dr.rate, gop.rr.rate)
gop.se.vector <-  c(gop.dd.se, gop.dr.se, gop.dd.se)


#1) All judges
pdf("figure1.pdf", height = 8.5, width = 6.5)

y.offset <- 0 #just for hypo graph
layout(rbind(1,2,3,4), heights = c(2.7,2.7, 2.7,4))
par(mar = c(2,5.6, 2.8, 2))

#hypothetical data 1: no party or panel differences
hypo.vector.all <- c(.45, .45, .45)
plot(hypo.vector.all, y, axes = F, xlim = c(.2, .7), ylim = c(min(y)-.3, max(y) +.3), xlab = "", ylab = "",
      main = "", pch = 19, col = color.vector, type = "p", cex=point.size)
abline(h = y, lty="dotted")
axis(1, at = seq(.2,.7,.1), labels = F,  mgp = c(2,.7,0), tcl = F)
axis(2, at = y, labels = y.label, las =1, mgp = c(2,.7,0), cex.axis  = axis.size)
abline(h = y, lty="dotted")
mtext("Panel\ncolleagues", 2, line = 2.7, cex =1.1, font = 2)
mtext("A) Hypothetical: no panel or party differences", 3, line = 0, cex =1.5, font = 3)
text(.45, 2.57,"Democratic and Republican\njudges", cex =1.2)
text(.25,.3, "Low", xpd = NA, cex = 1.2)
text(.65, .3,  "High", xpd = NA, cex = 1.2)

#hypothetical data 2: no panel differences
hypo.vector.all <- c(.45, .45, .45)
hypo.vector.dem <- c(.6, .6,.6)
hypo.vector.gop <- c(.3, .3,.3)
plot(hypo.vector.all, y, axes = F, xlim = c(.2, .7), ylim = c(min(y)-.3, max(y) +.3), xlab = "", ylab = "",
      main = "", pch = 19, col = color.vector, type = "n")
points(hypo.vector.dem , y + y.offset, type = "p", col = color.vector, cex = point.size, pch=19)
points(hypo.vector.gop, y - y.offset, cex = point.size,  pch = 21, bg = "white")
abline(h = y, lty="dotted")
axis(1, at = seq(.2,.7,.1), labels = F,  mgp = c(2,.7,0), tcl = F)
axis(2, at = y, labels = y.label, las =1, mgp = c(2,.7,0), cex.axis  = axis.size)
abline(h = y, lty="dotted")
mtext("Panel\ncolleagues", 2, line = 2.7, cex =1.1, font = 2)
mtext("B) Hypothetical: party but not panel differences", 3, line = 0, cex =1.5, font = 3)
text(.64, 2.6,"Democratic\njudges", cex =1.2)
text(.26, 2.6,"Republican\njudges", cex =1.2)
text(.25,.3, "Low", xpd = NA, cex = 1.2)
text(.65, .3,  "High", xpd = NA, cex = 1.2)

#3)actual data:all judges
plot(all.mean.vector, y, axes = F, xlim = c(.2, .7),ylim = c(min(y)-.3, max(y) +.3), xlab = "", ylab = "", 
    main = "", pch = 19, col = color.vector, cex = point.size)
axis(1, at = seq(.2,.7,.1),  mgp = c(2,.7,0), cex.axis  = axis.size)
axis(2, at = y, labels = y.label, las =1, mgp = c(2,.7,0), cex.axis  = axis.size)
segments(all.mean.vector-1.96*all.se.vector, y, all.mean.vector+1.96*all.se.vector,y, col = color.vector, lwd = line.width)
abline(h = y, lty="dotted")
mtext("Panel\ncolleagues", 2, line = 2.7, cex =1.1, font = 2)
mtext("C) Actual: all judges", 3, line = 0, cex =1.5, font = 3)

#4) actual:dems vs. gop
plot(dem.mean.vector, y + y.offset, xlim = c(.2,.7), 
    ylim = c(min(y)-.3, max(y) +.3), type = "p", axes = F, xlab = "", ylab = "", pch = 19, 
    main = "",  col = color.vector, cex = point.size)
abline(h = y, lty="dotted")
segments(dem.mean.vector - 1.96*dem.se.vector, y + y.offset, dem.mean.vector + 1.96*dem.se.vector, y + y.offset, lwd = line.width, col = color.vector)
segments(gop.mean.vector - 1.96*gop.se.vector, y - y.offset, gop.mean.vector + 1.96*gop.se.vector, y - y.offset, lwd = line.width,
    lty = 1, col = color.vector)
points(gop.mean.vector, y - y.offset, cex = point.size,  pch = 21, bg = "white")
axis(1, at = seq(.2,.7,.1),  mgp = c(2,.7,0), cex.axis  = axis.size)
axis(2, at = y, labels = y.label, las =1, mgp = c(2,.7,0), cex.axis  = axis.size)
mtext("D) Actual: Republicans versus Democratic judges", 3, line = 0, cex =1.5, font = 3)
mtext("Panel\ncolleagues", 2, line = 2.7, cex =1.1, font = 2)
mtext("Proportion of votes that are liberal", 1, line =2.5, cex =1.3, font = 2)
	#add arrows to distinguish:
	#a) effect of CJ 
arrow.length <-.1
text.height <- 1
arrows(gop.mean.vector[3]+.005, 1.1, gop.mean.vector[2]-.005, 1.9, length  =arrow.length, lty = 1, col = "gray10")
arrows(dem.mean.vector[1]-.004, 2.9,dem.mean.vector[2]+.005, 2.1, length  =arrow.length, lty = 1, col = "gray10")
text(.3, 1.6, "Effect OF\ncounter-judge", srt=46, cex = text.height, font = 3)
text(.61, 2.3, "Effect OF\ncounter-judge", srt=20, cex = text.height, font =3)
#and effect on CJ
arrows(gop.mean.vector[2], 2,gop.mean.vector[1]-.01, 2.9, length  =arrow.length, lty = 6, col = "gray20")
arrows(dem.mean.vector[2], 2,dem.mean.vector[3]+.004, 1.1, length  =arrow.length, lty = 6, col = "gray20")
text(.41, 2.4, "Effect ON\ncounter-judge", srt=37, cex = text.height, font = 3)
text(.485, 1.5, "Effect ON\ncounter-judge", srt=31, cex = text.height, font =3)
#add legend for Rep/Dem judges in plat
text(.24, 2.53, "= Republican\njudges", cex = 1, col = "red")
points(.2, 2.63, pch = 21, bg = "white", cex = point.size)
text(.68, 1.3, "= Democratic\njudges", cex = 1, col = "blue")
points(.64,1.38, pch = 19, cex = point.size)

dev.off()